package com.yznote.cloudesk.common.tokenShare;

import com.yznote.cloudesk.common.constants.YCacheConstant;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.common.pojo.User;
import com.yznote.cloudesk.cache.yCache.YCache;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@Api(tags = "token管理")
@RestController
public class TokenRenew {
    @Autowired
    YCache yCache;
    @Autowired
    YTokenShare yTokenShare;

    @ApiOperation("续签token")
    @GetMapping("/tokenRenew")
    public Result tokenRenew(){
        User user = yTokenShare.get();
        Object o = yCache.tryGet(YCacheConstant.TOKEN,user.getUserId().toString());
        yCache.put(YCacheConstant.TOKEN,user.getUserId().toString(), o,20, TimeUnit.MINUTES);
        return Result.success(null);
    }

    @ApiOperation("禁用本用户token")
    @GetMapping("/stopToken")
    public Result stopToken(){
        Long userId = yTokenShare.get().getUserId();
        yCache.delayDelete(YCacheConstant.TOKEN,userId.toString());
        return Result.success(null);
    }

//    @ApiOperation("禁用token")
//    @GetMapping("/stopTokenBytoken")
//    public Result stopTokenBytoken(@RequestParam String token){
//        Long userId = yTokenShare.get().getUserId();
//        yCache.delayDelete(YCacheConstant.TOkEN,userId.toString());
//        return Result.success(null);
//    }
}
